<template>
  <basic-container>
    <avue-crud
      :option="option"
      :data="data"
      :page.sync="page"
      :permission="permissionList"
      :before-open="beforeOpen"
      :table-loading="loading"
      v-model="form"
      ref="crud"
      @search-change="searchChange"
      @search-reset="searchReset"
      @current-change="currentChange"
      @size-change="sizeChange"
      @refresh-change="refreshChange"
      @on-load="onLoad"
      @selection-change="selectionChange"
      :key="timer"
    >
      <template slot="menuLeft">
        <el-button type="warning" size="small" icon="el-icon-download" @click="$refs.exportComp.visible = true">导出</el-button>
      </template>
      <template slot="menuRight">
        <user-table-config :option="option" @confirm="(val) => handleSetUserConfig(val, pageCode)"></user-table-config>
      </template>
    </avue-crud>
    <export-comp
      ref="exportComp"
      page-api-url="mes-warehouse/preparation-transfer-record/page"
      :option="option"
      :page="page"
      :query="query"
      file-name="备料调拨记录"
    ></export-comp>
  </basic-container>
</template>

<script>
import { getList, getDetail } from '@/api/warehouse/preparationTranferRecord';
import { mapGetters } from 'vuex';
import exportComp from '@/components/export-comp';
export default {
  components: {
    exportComp
  },
  data() {
    return {
      pageCode: 'preparationTranferRecord',
      form: {},
      query: {},
      detailLoading: false,
      loading: true,
      timer: new Date().getTime(),
      page: {
        pageSize: 20,
        currentPage: 1,
        total: 0
      },
      detailPage: {
        pageSize: 20,
        currentPage: 1,
        total: 0
      },
      params: {},
      selectionList: [],
      flagDialog: false,
      currentRow: {},
      options: [],
      option: {
        height: 'calc(100vh - 520px)',
        columnBtn: false,
        calcHeight: 30,
        tip: false,
        // searchMenuSpan: 10,
        refreshBtn: true, //刷新按钮是否显示
        searchBtn: true, // 显示查询的按钮
        searchSpan: 5,
        border: true,
        index: true,
        dialogClickModal: false,
        addBtn: false,
        delBtn: false,
        editBtn: false,
        viewBtn: true,
        viewBtnText: '详情',
        width: '100',
        searchLabelWidth: 130,
        searchMenuPosition: 'right',
        searchShow: true,
        menuWidth: 130,
        indexLabel: '序号',
        column: [
          {
            label: '备料单号',
            prop: 'preparationOrderNo',
            searchOrder: 1,
            search: true
          },
          {
            label: '备料单行号',
            prop: 'preparationOrderLot'
          },
          {
            label: '物料编码',
            prop: 'partNo',
            search: true,
            searchOrder: 2
          },
          {
            label: '物料名称',
            prop: 'partName'
          },
          // {
          //   label: '内部批次',
          //   prop: 'lotNo'
          // },
          {
            label: '调出仓库',
            prop: 'outWarehouseCode'
          },
          {
            label: '调入仓库',
            prop: 'inWarehouseCode'
          },
          {
            label: '计划调拨数量',
            prop: 'planQuantity'
          },
          {
            label: '本次调拨数量',
            prop: 'transferQuantity'
          },
          // {
          //   label: '调拨人',
          //   prop: 'transferByName',
          //   search: true
          // },
          {
            label: '调拨时间',
            prop: 'transferTime'
          },
          {
            label: '备注',
            prop: 'remark'
          }
        ]
      },
      optionDialog: {
        height: 'calc(100vh - 400px)',
        calcHeight: 30,
        delBtn: false,
        editBtn: false,
        addBtn: false,
        refreshBtn: false, //刷新按钮是否显示
        columnBtn: false, //控制表格列是否显示按钮是否显示
        border: true,
        menuWidth: 100,
        menu: false, //表格操作栏是否显示
        indexLabel: '序号',
        column: [
          {
            label: '物料编码',
            prop: 'partNo'
          },
          {
            label: '物料名称',
            prop: 'partName'
          },
          {
            label: '包装条码',
            prop: 'packSn'
          },
          {
            label: '数量',
            prop: 'packQuantity'
          },
          {
            label: '储位',
            prop: 'areaName'
          },
          {
            label: '批次',
            prop: 'lotNo'
          },
          {
            label: '状态',
            prop: 'statusFormatter',
            searchLabelWidth: 90,
            span: 4
          }
        ]
      },
      data: [],
      dataDialog: []
    };
  },
  computed: {
    ...mapGetters(['permission']),
    permissionList() {
      return {};
    },
    isHasPermission() {},
    ids() {
      let ids = [];
      this.selectionList.forEach((ele) => {
        ids.push(ele.id);
      });
      return ids.join(',');
    }
  },
  methods: {
    init() {},
    // detailEvent(row) {
    //   this.currentRow = row;
    //   this.flagDialog = true;
    //   this.getPackDetail(row, this.detailPage);
    // },
    // getPackDetail(row, page) {
    //   this.detailLoading = true;
    //   getDetail({
    //     id: row.id
    //   }).then((res) => {
    //     let data = res.data.data;
    //     this.dataDialog = data.records || [];
    //     this.detailLoading = false;
    //     this.detailPage.total = data.total;
    //   });
    // },
    beforeOpen(done, type) {
      if (['view'].includes(type)) {
        getDetail({
          id: this.form.id
        }).then((res) => {
          const data = res.data.data;
          this.form = data;
        });
        done();
      }
    },
    searchReset(params, done) {
      this.query = {};
      this.page.currentPage = 1;
      this.page.pageSize = 15;
      this.onLoad(this.page, this.query);
    },
    searchChange(params, done) {
      this.query = params;
      this.page.currentPage = 1;
      this.onLoad(this.page, this.query);
      done();
    },
    selectionChange(list) {
      this.selectionList = list;
    },
    selectionClear() {
      this.selectionList = [];
      this.$refs.crud.toggleSelection();
    },
    currentChange(currentPage) {
      this.page.currentPage = currentPage;
      this.onLoad(this.page, this.params);
    },
    currentDetailChange(currentPage) {
      this.detailPage.currentPage = currentPage;
      // this.getPackDetail(this.currentRow, this.detailPage);
    },
    sizeChange(pageSize) {
      this.page.pageSize = pageSize;
      this.onLoad(this.page);
    },
    sizDetailChange(pageSize) {
      this.detailPage.pageSize = pageSize;
      // this.getPackDetail(this.currentRow, this.detailPage);
    },
    refreshChange() {
      this.onLoad(this.page);
    },
    onLoad(page, params = {}) {
      this.loading = true;
      getList(page.currentPage, page.pageSize, Object.assign(params, this.query)).then((res) => {
        const data = res.data.data;
        this.data = data.records;
        this.page.total = data.total;
        this.loading = false;
      });
    },
    newKey() {
      this.timer = new Date().getTime();
    }
  },
  mounted() {
    this.$nextTick(() => {
      this.$structuralSplit();
    });
  },
  watch: {}
};
</script>

<style lang="scss" scoped>
::v-deep .el-dialog__header {
  padding: 16px 24px;
  min-height: 20px;
  border-bottom: 1px solid #f0f0f0;
}
::v-deep .el-dialog__body {
  padding: 15px 24px;
  .avue-crud__menu {
    display: none;
  }
}
</style>
